package com.wshl.cloudservice.utils;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.wshl.cloudservice.R;

public class DialogUtils {


    /**
     * @param context
     * @param content   对话框内容
     * @param cancancel 触摸屏幕是否dialog消失 true 消失 false 不消失
     *                  isShowTitle 是否显示标题
     */
    public void showCustomdialog(Context context, String content, boolean cancancel, boolean isShowTitle, String title, String cancel, String confirm) {
        final Dialog dialog = new Dialog(context, R.style.myDialog);
        View view1 = View.inflate(context, R.layout.dialog, null);
        TextView tvContent = view1.findViewById(R.id.tv_content);

        //对话框内容
        tvContent.setText(content);

        TextView tvTitle = view1.findViewById(R.id.tv_title);//标题
        TextView tvCancel = view1.findViewById(R.id.tv_exit);//取消
        TextView tvConfirm = view1.findViewById(R.id.tv_confirm);//确定

        if (!TextUtils.isEmpty(title)) {
            tvTitle.setText(title);
        }
        if (!TextUtils.isEmpty(cancel)) {
            tvCancel.setText(cancel);
        }
        if (!TextUtils.isEmpty(confirm)) {
            tvConfirm.setText(confirm);
        }

        //是否显示标题
        if (isShowTitle) {
            tvTitle.setVisibility(View.VISIBLE);
        } else {
            tvTitle.setVisibility(View.GONE);
        }

        //取消
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialog != null) {
                    dialog.dismiss();
                }

                if (onDialogConfirm != null) {
                    onDialogConfirm.setCancel();
                }
            }
        });

        //确定
        tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialog != null) {
                    dialog.dismiss();
                }

                if (onDialogConfirm != null) {
                    onDialogConfirm.setConfirm();
                }
            }
        });

        dialog.setContentView(view1);
        dialog.setCancelable(cancancel);


        dialog.show();
    }



    public void showCustomdialog(Context context,boolean cancancel) {
        final Dialog dialog = new Dialog(context, R.style.myDialog);
        View view1 = View.inflate(context, R.layout.dialog1, null);


        dialog.setContentView(view1);
        dialog.setCancelable(cancancel);

        dialog.show();
    }


    public OnDialogConfirm onDialogConfirm;

    public void setOndialgConfirm(OnDialogConfirm ondialgConfirm) {

        onDialogConfirm = ondialgConfirm;

    }

    public interface OnDialogConfirm {

        void setConfirm();

        void setCancel();

        void getInput(String input);
    }
}
